//
//  AccountModel.m
//  CC
//
//  Created by Calvin on 5/13/15.
//  Copyright (c) 2015 Calvin. All rights reserved.
//

#import "AccountModel.h"

@implementation AccountModel
+(instancetype)accountModelWithDict:(NSDictionary *)dict
{
    AccountModel *model = [[AccountModel alloc] init];
    model.access_token =dict[@"access_token"];
    model.expires_in = dict[@"expires_in"];
    model.uid = dict[@"uid"];
    NSDate *now=[NSDate date];
    model.expires_time = [now dateByAddingTimeInterval:model.expires_in.doubleValue];
    return model;
}

-(id)initWithCoder:(NSCoder *)aDecoder
{
    if (self=[super init]) {
        self.access_token = [aDecoder decodeObjectForKey:@"access_token"];
        self.expires_in = [aDecoder decodeObjectForKey:@"expires_in"];
        self.uid = [aDecoder decodeObjectForKey:@"uid"];
        self.expires_time = [aDecoder decodeObjectForKey:@"expires_time"];
        self.name = [aDecoder decodeObjectForKey:@"name"];
    }
    return self;
}

-(void)encodeWithCoder:(NSCoder *)aCoder
{
    [aCoder encodeObject:self.access_token forKey:@"access_token"];
    [aCoder encodeObject:self.expires_in forKey:@"expires_in"];
    [aCoder encodeObject:self.uid forKey:@"uid"];
    [aCoder encodeObject:self.expires_time forKey:@"expires_time"];
    [aCoder encodeObject:self.name forKey:@"name"];
}

@end
